<template>
  <download-excel
    :fetch="fetchData"
    :fields="json_fields"
    worksheet="My Worksheet"
    :name="json_name"
    class="excel"
  >
    <el-button class="el-icon-download" type="primary" style="margin-left:10px">下载模板</el-button>
  </download-excel>
</template>

<script>
export default {
  props: {
    list: Array,
    json_fields: Object,
    json_name: String
  },
  data() {
    return {

    }
  },
  methods: {
    fetchData() {
      const excelList = []
      console.log('this.list')
      console.log(this.list)
      // this.list是从后台接口获取的一组JSON数据（注意：使用forEach前，先判断数组存不存在！）
      this.list.forEach((item) => {
        excelList.push(item)
      })
      console.log('excelList')
      console.log(excelList)
      return excelList
    }
  }
}
</script>

<style lang="sass" scoped>
</style>
